package org.edu.modules.growth.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.edu.common.api.vo.Result;
import org.edu.common.system.base.controller.BaseController;
import org.edu.modules.growth.config.UateTimeTypeEnum;
import org.edu.modules.growth.entity.VeJsczUateProject;
import org.edu.modules.growth.service.IVeJsczUateProjectService;
import org.edu.modules.growth.vo.DictVo;
import org.edu.modules.growth.vo.QueryCondition;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags="教职工考核管理-考核项目设置")
@RestController
@RequestMapping("jsczUateProject")
@Slf4j
@AllArgsConstructor
public class VeJsczUateProjectController extends BaseController<VeJsczUateProject, IVeJsczUateProjectService> {

    private IVeJsczUateProjectService mIVeJsczUateProjectService;

    @ApiOperation(value = "考核时间字典")
    @PostMapping("/getDict")
    public Result<List<DictVo>> getDict( ) {
        return Result.OK(UateTimeTypeEnum.getDict());
    }

    /**
     * 分页查询信息
     */
    @ApiOperation(value = "分页查询信息")
    @PostMapping("/selectPage")
    public Result<?> selectPage(@RequestBody QueryCondition queryCondition ) {
        return Result.OK(mIVeJsczUateProjectService.selectPage(queryCondition));
    }


    /**
     * 保存与编辑
     */
    @ApiOperation(value = "保存与编辑考核项目")
    @PostMapping("/addOrUpdate")
    public Result<?> addOrUpdate(@RequestBody VeJsczUateProject dto) {
        if( dto.getId() != null ){
            dto.setTerminalId(null) ;
            return Result.OK(mIVeJsczUateProjectService.updateById(dto));
        }
        dto.setTerminalId(1L) ;
        return Result.OK(mIVeJsczUateProjectService.save(dto));
    }

    /**
     * 根据id详情
     */
    @ApiOperation(value = "根据id详情")
    @PostMapping("/getDetail")
    public Result<VeJsczUateProject> getDetail(@RequestParam("id") Long id) {
        return Result.OK(mIVeJsczUateProjectService.getById(id));
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @PostMapping("/removeById")
    public Result<?> removeById(@RequestParam("id") Long id) {
        return Result.OK(mIVeJsczUateProjectService.removeById(id));
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除")
    @PostMapping("/removeByIds")
    public Result<?> removeByIds(@RequestBody List<Long> ids) {
        if( !CollectionUtils.isEmpty(ids) ){
            return Result.OK(mIVeJsczUateProjectService.removeByIds(ids));
        }
        return Result.error( "传输参数为空！" );
    }

    /**
     * 获取期初或期末考核项目信息
     */
    @ApiOperation(value = "获取期初或期末考核项目")
    @PostMapping("/getProject")
    public Result<?> getProject(@RequestParam String type) {
        List<String> list = Lists.newArrayList(type,"SY") ;
        //创建查询的条件
        QueryWrapper<VeJsczUateProject> wrapper = new QueryWrapper<>() ;
        wrapper.in("type",list) ;
        wrapper.eq("status",1) ;
        wrapper.orderByAsc("listSort");
        return Result.OK(mIVeJsczUateProjectService.list(wrapper));
    }



}
